<?
	/* Se asegura que el archivo es incluido por el index */
	defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
		$this->oTmpObject = new Menu_frm( $this );

	class Menu_frm extends Frm
	{
	function setValue ( $ncMenu )
		{
			$cSql = "SELECT *
				FROM gtMenu
				WHERE ncMenu = $ncMenu";
			$aDatos = $this->oDatabase->getArray($cSql);
			$this->setFieldsArray ( $aDatos );
			$this->armarParametros();
		}
	function armarParametros()
	{
		if ( $this->aFields['nModo']->getValue() == 3)
		{
			foreach(explode('&', str_replace('&amp;', '&', $this->aFields['cUrl']->getValue()) )   as $cParametro )
			{
				list( $cVariable, $cValor ) = explode('=', $cParametro);
				$aVariables[$cVariable] = $cValor ;
			}
			if ( $aVariables[mo] && $aVariables[ac] )
			{
				$this->aFields['cUrl']->setValue('mo='. $aVariables[mo] . '&ac=' .  $aVariables[ac] );
				$oModule =& loadModule($aVariables[mo]);
				$oModule->loadTemplatePage($aVariables[ac]);
				foreach($oModule->aDatos[$aVariables[ac]][aParametros] as  $aParametro)
				{
					$cListaParam .= $aParametro[0] . ',';
					$this->aFields[$aParametro[0]]		= new InputText( $aParametro[1], $aParametro[0], $aVariables[$aParametro[0]] );
				}
				$this->aFields['cListaParam']->setValue( $cListaParam );
			}
		}
	}
	function Menu_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
			$this->aFields['ncMenu']						= new Input( "Codigo", "ncMenu" , '', false, true);
			$this->aFields['ncMenuPadre']				= new InputList( "Padre", "ncMenuPadre" );
			$this->aFields['cdMenu']						= new InputText( "Menu", "cdMenu" );
			$this->aFields['nModo']						= new InputList( "Tipo de link","nModo" );
			$this->aFields['nVista']						= new InputList( "Paneles","nVista" );
			$this->aFields['cUrl']							= new InputText( "Url", "cUrl" );
			$this->aFields['ncEstadoPublicacion']	= new InputList( "Estado" , "ncEstadoPublicacion" );
			$this->aFields['bExpandido']				= new InputList( "Expandido", "bExpandido" );
			$this->aFields['cDescripcion']				= new InputText( "Descripcion", "cDescripcion" );
			$this->aFields['cListaParam']				= new Input( '', 'cListaParam', '' , false, true);
			$this->aFields['nOrden']						= new InputNumber( "Orden", "nOrden" );
			$this->aFields['aRotulo']					= new InputCheck( "Tags", "aRotulo" );
			$this->armarParametros();
		}
	function initializeForm()
		{
			// Si viene el Ubicacion hace el retrieve
				if ( $this->isRetrievable() && $this->aFields['ncMenu']->getValue() )
				{
					$this->setValue( $this->aFields['ncMenu']->getValue() );
				}
			// Configura el Titulo
				$this->setLabel( "Menu" );
			$this->setMultiLanguage();
			return true;
		}
	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
					case 'ncMenuPadre':
						$cSql = "SELECT ncMenu,  cdMenu FROM gtMenu";
						if ( $this->aFields['ncMenu']->getValue() ) $cSql .= " WHERE ncMenu <> " . $this->aFields['ncMenu']->getValue();
						$oField->setLanguage('es');
						$oField->setMatrix($this->oDatabase->getMatrix($cSql));
						$oField->setMandatory($this->isMandatory);
					break;
					case 'cUrl':
						if ( $this->aFields['nModo']->getValue()	== 1 ) 
						{
							$oField->setValue('');
							$oField->setHidden();
						} else
						{
							if ( $this->aFields['nModo']->getValue()	== 2 ) 
								$oField->setValue( 'mo=portal&amp;ac=componentes');
							if ( $this->aFields['nModo']->getValue()	== 3 ) 
							{
								$oField = new InputList( "Url","cUrl" , $oField ->getValue());
								global $aInstallModules;
								foreach ( $aInstallModules as $cKey => $aInstallModule )
								{
									if ( $cKey != 'base' )
									{
										$oModule =& loadModule($cKey );
										$aData = $oModule->getTemplatesArray();
										foreach($aData as $cNombre)
											$oField->addOption( 'mo=' .$cKey. '&ac=' . $cNombre,  $cKey  . ' > ' . $cNombre);
									}
								}
							}
						}
						//$oField->setOnChangeAutoSubmit($this);
					break;
					case 'cdMenu':
						$oField->setMultiLanguage();
						//if( $this->getOptionsLevel() == 2 )
							//$oField->setMultilanguageStyle( MULTILANGUAGE_VERTICAL);
					break;
					case 'nVista':
						if ( $this->aFields['nModo']->getValue()	== 2 ) 
						{
							$oField->addOption( 0, 'Sin paneles' );
							$oField->addOption( 1, 'Con panel Izquierdo' );
							$oField->addOption( 2, 'Con panel derecho' );
							$oField->addOption( 3, 'Con ambos paneles' );
						}	else
							$oField->setHidden();
					break;
					case 'nModo':
						$oField->setDefault(2);
						$oField->addOption( 1, 'Item de menu solamente' );
						$oField->addOption( 2, 'Pagina de componentes' );
						$oField->addOption( 3, 'Templates' );
						$oField->addOption( 4, 'Popin' );
						$oField->addOption( 5, 'Externo' );
						$oField->setOnChangeAutoSubmit($this);
					break;
					case 'cDescripcion':
						$oField->setLength(4096);
						if( $this->getOptionsLevel() == 2 )
						{
							$oField->setMultiLanguage();
						}
					break;
					case 'ncEstadoPublicacion':
						$cSql = "SELECT ncEstadoPublicacion, cdEstadoPublicacion FROM gcEstadoPublicacion";
						$oField->setMatrix($this->oDatabase->getMatrix($cSql));
						$oField->setDefault(2);
						$oField->setMandatory($this->isMandatory());
						break;
					case 'aRotulo':
					if ($this->aFields['ncMenu']->getValue()  )
					{
						$cSql = "SELECT Par.ncRotulo, Par.cdRotulo, Tab.ncMenu
											FROM gtRotuloMenu as Par
												LEFT JOIN gtMenuRotulo as Tab
													ON Par.ncRotulo = Tab.ncRotulo
													AND Tab.ncMenu = " . $this->aFields['ncMenu']->getValue()  . "
											ORDER BY Par.cdRotulo";
					} else
					{
						$cSql = "SELECT ncRotulo, cdRotulo
											FROM gtRotuloMenu";
					}
					$oField->setMatrix( $this->oDatabase->getMatrix( $cSql ) );
					$oField->setMultiple( true );
				break;
				case 'bExpandido':
						$oField->setBool();
						$oField->setDefault(0);
					break;
			}
 		}
	}
?>